const UserKey = 'UserKey'
const TokenKey = 'TokenKey'

// 使用 localStorage 持久化存储（可根据需求改用 sessionStorage）
export function getTokenLocal() {
  return localStorage.getItem(TokenKey)
}

export function setTokenLocal(token) {
  return localStorage.setItem(TokenKey, token)
}

export function removeTokenLocal() {
  return localStorage.removeItem(TokenKey)
}

export function getUserLocal() {
  const user = localStorage.getItem(UserKey)
  return user ? JSON.parse(user) : null // 返回 null 而不是空对象
}

export function setUserLocal(user) {
  return localStorage.setItem(UserKey, JSON.stringify(user))
}

export function removeUserLocal() {
  return localStorage.removeItem(UserKey)
}